﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class Table : Item
{
    Queue<GameObject> chuans = new Queue<GameObject>();
    Object tuopan = null;

    // Start is called before the first frame update
    void Start()
    {
        tuopan = Resources.Load("Tray");
    }


    public bool EnqueueChuan(GameObject go)
    {
        if (chuans.Count < 5)
        {
            GameObject gotp = Instantiate(tuopan) as GameObject;
            go.transform.parent = gotp.transform;
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0));
            go = gotp;
            chuans.Enqueue(go);
            for (int i = 0; i < chuans.Count; i++)
            {
                chuans.ElementAt(i).transform.SetParent(transform, false);
                chuans.ElementAt(i).transform.localRotation = Quaternion.Euler(new Vector3(0, 90, 0));
                chuans.ElementAt(i).transform.localPosition = new Vector3(-0.6f + i * 0.4f, 0.77f, 0);
            }
            return true;
        }
        else return false;
    }

    public override GameObject[] TaskDequeue(int n)
    {
        int min = chuans.Count < n ? chuans.Count : n;
        GameObject[] rg = new GameObject[min];
        for (int i = 0; i < min; i++)
        {
            rg[i] = chuans.Dequeue();
        }
        for (int i = 0; i < chuans.Count; i++)
        {
            chuans.ElementAt(i).transform.localPosition = new Vector3(i * 0.13f - 0.26f, 0.045f, 0);
        }
        return rg;
    }
}
